<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-adverinfo-edit" th:object="${adverinfo}">
            <input id="advertinfoId" name="advertinfoId" th:field="*{advertinfoId}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">广告标题：</label>
				<div class="col-sm-8">
					<input id="biaoTi" name="biaoTi" th:field="*{biaoTi}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">广告链接：</label>
				<div class="col-sm-8">
					<input id="lianJie" name="lianJie" th:field="*{lianJie}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">显示顺序：</label>
				<div class="col-sm-8">
					<input id="shunXu" name="shunXu" th:field="*{shunXu}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">广告状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="${adverinfo.status == '0' ? true : false}" class="onoffswitch-checkbox" id="status" name="status">
						<label class="onoffswitch-label" for="status">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">广告照片：</label>
						<tr th:each="attachement:${attachements}">
							<div><td th:text="${attachement.mc}"/>&nbsp;&nbsp;&nbsp;<a style="color: red;" onclick="$(this).parent().remove();delAttach('${attachement.attachmentsId}');">删除</a></div>
						</tr>
						<div class="col-sm-8">
							<input type="file" name="files" onchange="addFile(this)" >
						</div>
					</div>
				</div>
			</div>

		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		function addFile(obj) {
			var o = $(obj);
			var len = o.parent().find('input').length;
			if(o[0].value == ''){
				if(len > 1){
					o.remove();
				}
			}else{
				o.parent().append('<input type="file" name="files" onchange="addFile(this)">')
			}
		}
		var prefix = ctx + "system/adverinfo";
		$("#form-adverinfo-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		var prefix2 = ctx + "system/attachements"
		function submitHandler() {
			if ($.validate.form()) {
				var ids = '';
				$(':file').each(function(i){
					if($(this).val() != ''){
						$(this).attr('id', 'img'+i)
						ids += ',img'+i;
					}
				});
				$.operate.save2(prefix + "/edit", $('#form-huiyuan-edit').serialize());
			}
		}

		//附件删除
		function delAttach(val){
			$.ajax({
				type: 'GET',
				url:prefix2+'/remove',
				data: {id:val}
			});
		}
	</script>
</body>
</html>
